package br.ucb.servlets.cliente;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.ucb.dao.ClienteDAO;
import br.ucb.entidade.Cliente;
import br.ucb.entidade.Usuario;
import br.ucb.service.ClienteService;
import br.ucb.service.impl.ClienteServiceImpl;
import br.ucb.servlets.AbstractPapirosServlet;
import br.ucb.servlets.util.PapirosUtil;

public class BuscarClienteServlet extends AbstractPapirosServlet<Cliente, ClienteService, ClienteDAO> {

	private static final long serialVersionUID = 1L;

	@Override
	protected void processaRequisicao(HttpServletRequest req,
			HttpServletResponse resp)throws ServletException,IOException {
		
		setEntidadeService(new ClienteServiceImpl());
		setEntidade(new Cliente());
		
		if(!PapirosUtil.isUserLogged(req)){
			forward(req, resp, "/jsp/seguranca/login.jsp");
		}else{
			Usuario user = (Usuario)req.getSession().getAttribute("user");
			getEntidade().setCpf(user.getCpf());
			req.setAttribute("cliente", findByKey(getEntidade(), req));
			
			forward(req, resp, "/jsp/restrito/alterarCliente.jsp");
		}
	}
	
}
